package com.azzcs.juc.countdownlatch;

import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * @Author: wzg
 * @Date: 2021/6/17 上午11:25
 */
public class Main {
    public static void main(String[] args) throws InterruptedException {
        Random random = new Random();
        CountDownLatch latch = new CountDownLatch(5);
        for (int i = 1; i < 6; i++) {
            new Thread(()->{
                try {
                    TimeUnit.MILLISECONDS.sleep(random.nextInt(1000));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"is run...");
                latch.countDown();
            },"thread"+i).start();
        }
        latch.await();
        System.out.println("main run...");
    }
}
